package com.fy.fyzf.utils;

import android.content.Context;
import android.widget.ImageView;

import com.fy.fyzf.api.ApiConstant;
import com.mob.MobSDK;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

public class ShareHelper {
    private Context mContext;

    public ShareHelper(Context context) {
        mContext = context;
    }


    public void shareWx(String imgUrl,String shareUrl){
        Platform.ShareParams sp = new Platform.ShareParams();
        sp.setTitle("安联选房");
        sp.setTitleUrl("http://sharesdk.cn"); // 标题的超链接
        sp.setText("专业团队，优质房源");
        sp.setImageUrl(imgUrl);
        sp.setShareType(Platform.SHARE_WEBPAGE);
        sp.setUrl(shareUrl);
        Platform platform = ShareSDK.getPlatform (Wechat.NAME);
        platform.share(sp);

        platform.setPlatformActionListener (new PlatformActionListener() {
            public void onError(Platform arg0, int arg1, Throwable arg2) {
                //失败的回调，arg:平台对象，arg1:表示当前的动作，arg2:异常信息
            }
            public void onComplete(Platform arg0, int arg1, HashMap arg2) {
                //分享成功的回调
                onShareListener.shareSuccess();
            }

            public void onCancel(Platform arg0, int arg1) {
                AppUtils.showToast("分享取消");
                //取消分享的回调
            }
        });

       /* oks.setPlatform(Wechat.NAME);
        oks.setTitle("安联选房");
//        oks.setTitleUrl("http://sharesdk.cn");
        // text是分享文本，所有平台都需要这个字段
        oks.setText("专业团队，优质房源");
        // setImageUrl是网络图片的url
        oks.setImageUrl(imgUrl);
        oks.setUrl("https://www.fuyinzf.com/shareHousing/getHousing?housingId="+housingId);
        oks.show(MobSDK.getContext());
        oks.setCallback(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                AppUtils.showToast("分享onComplete");
            }
            @Override
            public void onError(Platform platform, int i, Throwable throwable) {

            }
            @Override
            public void onCancel(Platform platform, int i) {
                AppUtils.showToast("分享取消");
            }
        });*/

    }


    public void shareWechatMoments(String imgUrl,String shareUrl){
        /*OnekeyShare oks = new OnekeyShare();
        // title标题，微信、QQ和QQ空间等平台使用
        oks.setPlatform(WechatMoments.NAME);
        oks.setTitle("安联选房");
        // titleUrl QQ和QQ空间跳转链接
        oks.setTitleUrl("http://sharesdk.cn");
        // text是分享文本，所有平台都需要这个字段
        oks.setText("专业团队，优质房源");
        // setImageUrl是网络图片的url
        oks.setImageUrl(imgUrl);
        oks.setUrl("https://www.fuyinzf.com/shareHousing/getHousing?housingId="+housingId);
        oks.show(MobSDK.getContext());
        return oks;*/

        Platform.ShareParams sp = new Platform.ShareParams();
        sp.setTitle("安联选房");
        sp.setTitleUrl("http://sharesdk.cn"); // 标题的超链接
        sp.setText("专业团队，优质房源");
        sp.setImageUrl(imgUrl);
        sp.setShareType(Platform.SHARE_WEBPAGE);
        sp.setUrl(shareUrl);
        Platform platform = ShareSDK.getPlatform (WechatMoments.NAME);
        platform.share(sp);

        platform.setPlatformActionListener (new PlatformActionListener() {
            public void onError(Platform arg0, int arg1, Throwable arg2) {
                //失败的回调，arg:平台对象，arg1:表示当前的动作，arg2:异常信息
            }
            public void onComplete(Platform arg0, int arg1, HashMap arg2) {
                onShareListener.shareSuccess();
                //分享成功的回调
//                mContext.
            }
            public void onCancel(Platform arg0, int arg1) {
                AppUtils.showToast("分享取消");

            }
        });
    }

    private onShareListener onShareListener;
    public void setShareListener (onShareListener listener){
        onShareListener = listener;
    }
    public interface onShareListener {
        void shareSuccess();
    }
}
